package com.qf.s;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qf.pojo.Clazz;
import com.qf.pojo.Student;

import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project day44-1
 * @Package com.qf.s
 * @Description:
 * @Date 2022/5/16 23:08
 */
public class TestFastJson {

    public static void main(String[] args) {
        String jsonStr= "{" +
                "    \"id\":2203, \"name\": \"bk-java2203\", \"studentList\": [" +
                "        {\"id\":1, \"name\": \"董峰\", \"sex\":\"男\"}," +
                "        {\"id\":2, \"name\": \"白靖阳\", \"sex\":\"男\"}," +
                "        {\"id\":3, \"name\": \"邹威庭\", \"sex\":\"男\"}" +
                "    ]" +
                "}";


        Clazz aClass = JSON.parseObject(jsonStr, Clazz.class);
        System.out.println(aClass);
        String s = JSON.toJSONString(aClass);
        System.out.println(s);
        String jsonStr2 =
                "[" +
                        "    {\"id\":1, \"name\":\"董峰\", \"sex\":\"男\"}," +
                        "    {\"id\":2, \"name\":\"白靖阳\", \"sex\":\"男\"}," +
                        "    {\"id\":3, \"name\":\"邹威庭\", \"sex\":\"男\"}" +
                        "]";
        List<Student> students = JSON.parseArray(jsonStr2, Student.class);
        System.out.println(students);

    }
}
